// SPDX-License-Identifier: GPL-2.0
/*
 * KERNEL THREAD
 *
 * (C) 2024.05.20 BiscuitOS <buddy.zhang@aliyun.com>
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/delay.h> 

static struct task_struct *kthread;

static int BiscuitOS_kfn(void *data)
{
	printk("KTHREAD RUNNING.\n");

	/* KTHREAD MAIN ROUTE */
	while (!kthread_should_stop()) {
		/* TODO */
		ssleep(1);
	}

	printk("KTHREAD STOPING\n");

	return 0;
}

static int __init BiscuitOS_init(void)
{
	/* CREATE AND RUNNING KTHREAD */
	kthread = kthread_run(BiscuitOS_kfn, NULL, "BiscuitOS-kthread");
	if (IS_ERR(kthread))
		return PTR_ERR(kthread);

	return 0;
}

static void __exit BiscuitOS_exit(void)
{
	/* KTHREAD STOP */
	kthread_stop(kthread);
}

module_init(BiscuitOS_init);
module_exit(BiscuitOS_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("BiscuitOS <buddy.zhang@aliyun.com>");
MODULE_DESCRIPTION("BiscuitOS SCHEDULE SUBSYSTEM");
